﻿using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace TSharp.Core.Mvc.XmlRouting.Culture
{
    internal class CulturePrefixRule : IRouteConstraint
    {
        private readonly IEnumerable<string> cultureConllection =
            CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(p => p.Name.ToLower());

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values,
                          RouteDirection routeDirection)
        {
            if (values[parameterName] != null)
                return cultureConllection.Contains(values[parameterName].ToString().ToLower());
            else
                return false;
        }
    }
}